package cn.nhic.web.controller;
/**
 * Created by duweiping on 2024/9/4 1:05
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 生命周期
 * @author duweiping
 * @date 2024/9/4 1:05
 *
 * 同学们自己写一下，太简单了，我这边就不写了。
 * TODO 思考题：大家判断LifeCircleServlet类中执行方法的顺序
 */
@WebServlet(urlPatterns = "/life_circle_servlet")
public class LifeCircleServlet extends HttpServlet {
    /**
     * 1
     */
    public LifeCircleServlet() {
        // 1.1
        super();
        // 1.2
        System.out.println("new HttpServlet()");
    }

    /**
     * 2
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doGet(req, resp);
        System.out.println("servlet service().doGet()");
    }

    /**
     * 3
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
        System.out.println("servlet service()");
    }

    /**
     * 4
     */
    @Override
    public void destroy() {
        super.destroy();
        System.out.println("servlet destroy");
    }

    /**
     * 5
     * @throws ServletException
     */
    @Override
    public void init() throws ServletException {
        super.init();
        System.out.println("GenericServlet init()");
    }
}
